import { Component, OnInit, ViewChild, ViewContainerRef, ComponentRef, ComponentFactoryResolver, EventEmitter } from '@angular/core';
import * as flatpickr from 'flatpickr';
import { zh } from "flatpickr/dist/l10n/zh.js";
import { AppPaginationComponent, PaginationModel } from "../../../../../widgets/pagination/pagination.component";
import { environment } from "../../../../../../environments/environment";
import * as _ from "lodash";
import { FlowInfoComponent } from '../../modal/flow-info/flow-info.component';
import { RouteModeService } from './route-mode.service';
import { ApplyQDIINameComponent } from '../../modal/apply-qdiiname/apply-qdiiname.component';
import { DataService } from '../../../../../services/data.service';
import { Util } from '../../../../../common/util';
import { SelectItem } from 'primeng/components/common/api';
import { CommitComponent } from '../../modal/commit/commit.component';
import { SubmitComponent } from '../../modal/submit/submit.component';
import { RevokeComponent } from '../../modal/revoke/revoke.component';
import { RouteRevokeComponent } from '../../modal/route-revoke/route-revoke.component';
@Component({
  selector: 'app-route-mode',
  templateUrl: './route-mode.component.html',
  styleUrls: ['./route-mode.component.scss'],
  providers: [RouteModeService]
})
export class RouteModeComponent implements OnInit {
  // 分页列表post数据
  public postBody = {
    pageIndex: 1,
    pageSize: 50,
    sOprDateStart: "",//发起日期
    sOprDateEnd: "",//结束日期
    nBatchNoStart: "",//开始批次
    nBatchNoEnd: "",//结束批次
    // sFileName: "",//文件名称
    // commitOpr: ""//提交人
  }
  //下拉多选option数据
  public dictionaryInfo: SelectItem[];
  // 撤销modal
  @ViewChild("routeRevokeModal", { read: ViewContainerRef })
  routeRevokeModal: ViewContainerRef;
  revokeComponent: ComponentRef<RouteRevokeComponent>;
  // 保存并提交modal
  @ViewChild("routeSubmitModal", { read: ViewContainerRef })
  routeSubmitModal: ViewContainerRef;
  commitComponent: ComponentRef<SubmitComponent>;
  //查看流程信息
  @ViewChild("flowInfo1", { read: ViewContainerRef })
  flowInfo1: ViewContainerRef;
  flowInfoComponent: ComponentRef<FlowInfoComponent>;
  // 适用QDII名称modal
  @ViewChild("applyQDIIName1", { read: ViewContainerRef })
  applyQDIIName1: ViewContainerRef;
  applyQDIINameComponent: ComponentRef<ApplyQDIINameComponent>;

  public elementShow: any = [];
  // lodash
  public _: any = _;
  // 菜单数据
  public menuData: any;
  //列表克隆数据
  public cloneList: any;
  // 菜单权限set
  public menuResourceSet: any = [];
  //全选按钮
  public isCheckedAll: any = false;
  //分页配置
  public listPageInfo = {
    currentPageNum: 1,
    pageSize: 50,
    totalPages: 1,
    total: 0,
    pagesShow: 5,
    startRow: 0,
    endRow: 0,
    pageList: [5, 10, 25, 50, 100]
  };
  //条目修改下拉框绑定数据
  public dataInfo: any = {
    sItemType: '',
    sFileSource: '',
    sFileName: '',
    sFundType: '',
    sFundGroupdsZh: '',
    sFundGroupds: ''
  }
  //字典值列表
  public dictionaryList: any = {
    NX_SOURCE: [],//条款出处
    QD_ACCOUNT_TYPE: [],//适用基金组类别
    QDII_RECORD_TYPE: [],//风控条目属性
    RISK_BOOLMBERG_CONTROL: []//bloomberg系统能否控制 
  }
  //条目历史列表
  public listData: any = [
  ];
  constructor(
    public resolver: ComponentFactoryResolver,
    public routeModeService: RouteModeService,
    public dataService: DataService
  ) { }

  // 显示查看流程信息modal
  showFlowInfo() {
    let count: any = this.entryCount();
    if (count.length == 1) {
      if (this.flowInfoComponent && this.flowInfoComponent.instance) {
        this.flowInfoComponent.destroy();
      }

      // 动态创建组件的实例
      const flowInfoComponent = this.resolver.resolveComponentFactory(FlowInfoComponent);
      this.flowInfoComponent = this.flowInfo1.createComponent(flowInfoComponent);
      this.flowInfoComponent.instance.item = count[0];
      console.log(count[0])

      window['$']('#flowInfo1').modal('show');
    } else {
      window['swal']("提示", "请选择一条数据进行查看", "warning")
    }
  }
  //判断选中的条目数量
  entryCount() {
    let entryList: any = [];
    _.forEach(this.listData, item => {
      if (item.isChecked) {
        entryList.push(item);
      }
    })
    return entryList;
  }
  //修改勾选的条目
  changeCheckedInfo(field) {
    let that = this;
    _.forEach(this.listData, (item, index) => {
      if (item.isChecked) {
        switch (field) {
          case 'sItemType':
            // item.sItemTypeZh = that.getValueByKey(that.dataInfo.sItemType, 'QDII_RECORD_TYPE')
            item.sItemType = that.dataInfo.sItemType;
            that.inputChange(index, item.sItemType, field)
            break;
          case 'sFileSource':
            // item.sFileSourceZh = that.getValueByKey(that.dataInfo.sFileSource, 'NX_SOURCE')
            item.sFileSource = that.dataInfo.sFileSource;
            that.inputChange(index, item.sFileSource, field)
            break;
          case 'sFileName':
            item.sFileName = that.dataInfo.sFileName;
            that.inputChange(index, item.sFileName, field)
            break;
          case 'sFundType':
            // let value3 = that.getValueByKey(that.dataInfo.sFundType, 'QD_ACCOUNT_TYPE')
            window['$']('#QDIIRouteFundType' + index).selectpicker('val', that.dataInfo.sFundType);
            item.sFundType = that.dataInfo.sFundType;
            that.inputChange(index, item.sFundType, field)
            break;
          case 'sFundGroupdsZh':
            item.sFundGroupdsZh = that.dataInfo.sFundGroupdsZh;
            item.sFundGroupds = that.dataInfo.sFundGroupds;
            that.inputChange(index, item.sFundGroupdsZh, field)
            break;
        }
      }
    })
  }
  ngOnInit() {
    let that = this;
    // 初始化日期控件
    flatpickr.localize(zh);
    // 多选下拉框
    window['$'](".select2").select2();
    this.loadlist()
    // 字典值
    this.dictionaryList = JSON.parse(localStorage.getItem("dictionaryList"));

    Util.loadSelect(this.dictionaryList.QD_ACCOUNT_TYPE, 'QDIIRouteFundType');
    this.dictionaryInfo = Util.loadPrimeSelect(this.dictionaryList.QD_ACCOUNT_TYPE);
    // this.controlDom();
    this.dataService.QDIIInputModelEmitter = new EventEmitter();
    this.dataService.QDIIInputModelEmitter.subscribe((value: any) => {
      if (value) {
        switch (value) {
          case 'routeModel':
            that.dataInfo.sFundGroupdsZh = that.dataService.QDIINameList;
            that.dataInfo.sFundGroupds = that.dataService.QDIIIdList;
            that.changeCheckedInfo('sFundGroupdsZh');
            window['$']('#applyQDIIName1').modal('hide');
            break;
          case 'index':
            that.listData[that.dataService.QDIIIndexId].sFundGroupdsZh = that.dataService.QDIINameList;
            that.listData[that.dataService.QDIIIndexId].sFundGroupds = that.dataService.QDIIIdList;
            window['$']('#applyQDIIName1').modal('hide');
            break;
          case 'refreshRouteList':
            that.loadlist();
            break;
          case 'revokeModel':
            that.loadlist();
            break;
        }
      }
    })
    // 权限处理
    this.dataService.initTree.subscribe((data) => {
      if (data) {
        let SessionMenuData = sessionStorage.getItem('menu');
        this.menuData = JSON.parse(SessionMenuData)
        this.menuResourceSet = [];
        _.forEach(this.menuData, (item, index) => {
          if (item.sName == '风控管理') {
            _.forEach(item.children, (it, idx) => {
              if (it.sName == 'QDII条目管理') {
                _.forEach(it.children, (ite, i) => {
                  if (ite.sName == '录入QDII条目') {
                    that.menuResourceSet = ite.resourceSet
                    sessionStorage.setItem('btn-QDII', this.menuResourceSet);
                  }
                })
              }
            })
          }
        })
      }
    })
    let SessionMenuData = sessionStorage.getItem('menu');
    this.menuData = JSON.parse(SessionMenuData)
    this.menuResourceSet = [];
    _.forEach(this.menuData, (item, index) => {
      if (item.sName == '风控管理') {
        _.forEach(item.children, (it, idx) => {
          if (it.sName == 'QDII条目管理') {
            _.forEach(it.children, (ite, i) => {
              if (ite.sName == '录入QDII条目') {
                that.menuResourceSet = ite.resourceSet
                sessionStorage.setItem('btn-QDII', this.menuResourceSet);
              }
            })
          }
        })
      }
    })
  }
  // ngAfterViewChecked() {
  //   let that = this;
  //   if(this.listData != null){
  //     for (let i = 0; i < this.listData.length; i++) {
  //       // Util.loadSelect(this.dictionaryList.QD_ACCOUNT_TYPE, 'QDIIRouteFundType' + i)
  //       // window['$']('#QDIIRouteFundType' + i).selectpicker('val', this.listData[i].sFundType);
  //       if (this.listData[i + 1] != undefined) {
  //         if (this.listData[i].nQjId == this.listData[i + 1].nQjId) {
  //           window['$']('#routeCheck' + i).remove();
  //           _.forIn(that.listData[i], (item1, key1) => {
  //             let index1 = i + 1;
  //             let index2 = i + 2;
  //             let id1 = "#route-table tbody tr:nth-child(" + index1 + ") td input[name=" + key1 + "]";
  //             let id2 = "#route-table tbody tr:nth-child(" + index2 + ") td input[name=" + key1 + "]";
  //             let id3 = "#route-table tbody tr:nth-child(" + index1 + ") td select[name=" + key1 + "]";
  //             let id4 = "#route-table tbody tr:nth-child(" + index2 + ") td select[name=" + key1 + "]";
  //             if (item1 == that.listData[i + 1][key1]) {
  //               window['$'](id1).removeClass('font-color');
  //               window['$'](id2).removeClass('font-color');
  //               window['$'](id3).removeClass('font-color');
  //               window['$'](id4).removeClass('font-color');
  //             } else {
  //               window['$'](id1).removeClass('font-color');
  //               window['$'](id3).removeClass('font-color');
  //             }
  //           })
  //         }
  //       }
  //     }
  //   }

  // }
  //根据编号是否相同操控dom
  controlDom() {
    let that = this;
    // console.log("调用了")
    setTimeout(() => {
      if (this.listData != null) {
        for (let i = 0; i < that.listData.length; i++) {
          
          if (that.listData[i + 1] != undefined) {
            if (that.listData[i].nQjId == that.listData[i + 1].nQjId) {
              window['$']('#routeCheck' + i).remove();
              _.forIn(that.listData[i], (item1, key1) => {
                let index1 = i + 1;
                let index2 = i + 2;
                let id1 = "#route-table tbody tr:nth-child(" + index1 + ") td[id=" + key1 + "]";
                let id2 = "#route-table tbody tr:nth-child(" + index2 + ") td[id=" + key1 + "]";
                let id3 = "#route-table tbody tr:nth-child(" + index1 + ") td select[name=" + key1 + "]";
                let id4 = "#route-table tbody tr:nth-child(" + index2 + ") td select[name=" + key1 + "]";
                let id5 = "#route-table tbody tr:nth-child(" + index1 + ") td div[id=" + key1 + "]";
                let id6 = "#route-table tbody tr:nth-child(" + index2 + ") td div[id=" + key1 + "]";
                if (item1 == that.listData[i + 1][key1]) {
                  window['$'](id1).removeClass('font-color');
                  window['$'](id2).removeClass('font-color');
                  window['$'](id3).removeClass('font-color');
                  window['$'](id4).removeClass('font-color');
                  window['$'](id5).removeClass('font-color');
                  window['$'](id6).removeClass('font-color');
                } else {
                  window['$'](id1).removeClass('font-color');
                  window['$'](id3).removeClass('font-color');
                  window['$'](id5).removeClass('font-color');
                }
              })
            }
          }
        }
      } else {
        this.controlDom();
      }
    });
  }
  // 列表全选
  checkedAll() {
    if (this.isCheckedAll) {
      // 更新为全选
      _.forEach(this.listData, (item, index) => {
        item.isChecked = true;
        if (this.listData[index + 1] != undefined) {
          if (this.listData[index].nQjId == this.listData[index + 1].nQjId) {
            this.listData[index].isChecked = false;
          }
        }
      });
    } else {
      // 更新为不全选
      _.forEach(this.listData, item => {
        item.isChecked = false;
      });
    }
  }
  // 列表是否全选
  ctrlCheckAll() {
    let that = this;
    let checkList = [];
    let repeatCount = 0;
    _.forEach(this.listData, (item, index) => {
      if (this.listData[index + 1] != undefined) {
        if (this.listData[index].nQjId == this.listData[index + 1].nQjId) {
          repeatCount++;
        }
      }
      if (item.isChecked == true) {
        checkList.push(item);
      }
    })
    if (checkList.length + repeatCount == this.listData.length) {
      this.isCheckedAll = true;
    } else {
      this.isCheckedAll = false;
    }
  }
  // 条数分页
  sizeChange(pageSize: number) {
    if (pageSize !== this.listPageInfo.pageSize) {
      this.listPageInfo.pageSize = pageSize;
      this.loadlist();
    }
  }
  // 列表分页
  pageNavigation(currentPageNum: number) {
    this.listPageInfo.currentPageNum = currentPageNum;
    this.loadlist(this.listPageInfo.currentPageNum, this.listPageInfo.pageSize);
  }
  //打开搜索modal
  showSearchModal() {
    window['$']('#search-modal').modal('show');
  }
  //适用QDII名称modal
  showApplyQDIIName(index?) {
    // 判断组件是否已创建，如果创建先注销
    if (this.applyQDIINameComponent && this.applyQDIINameComponent.instance) {
      this.applyQDIINameComponent.destroy();
    }
    // 动态创建组件的实例
    const applyQDIINameComponent = this.resolver.resolveComponentFactory(ApplyQDIINameComponent);
    this.applyQDIINameComponent = this.applyQDIIName1.createComponent(applyQDIINameComponent);
    if (index != null) {
      this.applyQDIINameComponent.instance.index = index;
      if (this.listData[index].sFundGroupdsZh != '' && this.listData[index].sFundGroupdsZh != null && this.listData[index].sFundGroupdsZh != undefined) {
        this.applyQDIINameComponent.instance.checkedIdList = this.listData[index].sFundGroupds.split(',');
        console.log(this.listData[index].sFundGroupds.split(','))
      }
    } else {
      this.applyQDIINameComponent.instance.modeType = 'route';
      if (this.dataInfo.sFundGroupdsZh != '' && this.dataInfo.sFundGroupdsZh != null && this.dataInfo.sFundGroupdsZh != undefined) {
        this.applyQDIINameComponent.instance.checkedIdList = this.dataInfo.sFundGroupds.split(',');
        console.log(this.dataInfo.sFundGroupds.split(','))
      }

    }
    window['$']('#applyQDIIName1').modal('show');
  }
  //查询分页列表
  loadlist(pageNum?, pageSize?) {
    let that = this;
    let listData = [];
    this.isCheckedAll = false;
    this.postBody.pageIndex = pageNum ? pageNum : this.listPageInfo.currentPageNum;
    this.postBody.pageSize = pageSize ? pageSize : this.listPageInfo.pageSize;
    this.routeModeService.routeModeList(this.postBody).subscribe(data => {
      if (data) {
        this.listData = data.list;
        _.forEach(this.listData, it => {
          if (it.sFundType != null) {
            it.sFundType = it.sFundType.split(",");
          }
        })
        this.cloneList = _.cloneDeep(this.listData);
        if(data.list.length>0){
          this.elementList(data.list.length);
        }
       
        this.controlDom();
        console.log(data);
        this.listPageInfo.currentPageNum = data.pageNum;
        this.listPageInfo.totalPages = data.pages;
        this.listPageInfo.total = data.total;
        this.listPageInfo.startRow = data.startRow;
        this.listPageInfo.endRow = data.endRow;
        window['$']('#search-modal').modal('hide');
      }
    })
  }

  //撤销
  recall() {
    let that = this;
    let checkedItem = [];
    let putBody = [];
    //用于判断是否选择了复核的数据
    // let sFlowStepList: any = [];
    _.forEach(that.listData, item => {
      if (item.isChecked == true) {
        checkedItem.push(item.nId);
        putBody.push(item)
        // if (item.sFlowStep == '1') {
        //   sFlowStepList.push(item)
        // }
      }
    });

    console.log(JSON.stringify(putBody))
    if (checkedItem.length != 0) {
      let list: any = [];
      // if (sFlowStepList.length > 0) {
      //   window['swal']("提示", "请选择流程状态为复核的数据进行撤销", "warning")
      // } else {
        _.forEach(putBody, it => {
          list.push(it.nBatchNo);
        })
        let repeatList = _.uniq(list);
        console.log(repeatList)
        if (repeatList.length > 1) {
          window['swal']("提示", "请不要进行跨批次操作", "warning")
        } else {
          let getBody = {
            "nIdList": checkedItem
          }
          that.routeModeService.lock(getBody).subscribe(data => {
            if (data == true) {
              that.showRevoke(checkedItem)
            } else {
              window['swal']("提示", "上锁失败", "warning");
            }
          })

        }
      // }

    }
    else {
      window['swal']("提示", "请选择一条或者多条数据进行撤销", "warning")
    }

  }
  //展示撤销modal
  showRevoke(item) {
    // 判断组件是否已创建，如果创建先注销
    if (this.revokeComponent && this.revokeComponent.instance) {
      this.revokeComponent.destroy();
    }
    if (item.length != 0) {
      // 动态创建组件的实例
      const revokeComponent = this.resolver.resolveComponentFactory(RouteRevokeComponent);
      this.revokeComponent = this.routeRevokeModal.createComponent(revokeComponent);
      this.revokeComponent.instance.RoutepostBody = item
      window['$']('#routeRevokeModal').modal('show');
    } else {
      window['swal']("提示", "请选择一条数据", "warning")
    }

  }
  //保存
  save() {
    let that = this;
    let putBody: any = [];
    let listData = _.cloneDeep(this.listData)
    let sFlowStepList: any = [];
    //用于判断数据是否已修改的数组
    let isChangeList: any = [];
    if (this.proofInfo()) {
      _.forEach(listData, item => {
        let isNull: any = true;
        if (item.isChecked) {
          delete item.isChecked;
          isChangeList.push(_.cloneDeep(item));
          delete item.auditOpr;
          delete item.auditOprDate;
          delete item.auditOprZh;
          delete item.commitOpr;
          delete item.commitOprDate;
          delete item.commitOprZh;
          //判断选中的对象的sFundType是否为数组
          if (Array.isArray(item.sFundType)) {
            item.sFundType = item.sFundType.join(',');
          }
          putBody.push(item)
          sFlowStepList.push(item.sFlowStep);
        }
      })
      let reviewList = _.filter(sFlowStepList, item => {
        return item == "2";
      })
      console.log(JSON.stringify(putBody))
      if (putBody.length < 1) {
        window['swal']("提示", "请选择需要操作的数据", "warning")
      } else if (putBody.length > 1) {
        let list: any = [];
        _.forEach(putBody, it => {
          list.push(it.nBatchNo);
        })
        let repeatList = _.uniq(list);
        if (repeatList.length > 1) {
          window['swal']("提示", "请不要进行跨批次操作", "warning")
        } else {
          if (reviewList.length > 0) {
            window['swal']("提示", "复核中的流程不允许更改并保存", "warning")
          } else {
            //判断未经修改的条目录入数据不能进行保存
            let list: any = [];
            _.forEach(isChangeList, item => {
              let item2 = _.filter(that.cloneList, (it: any) => { return item.nId == it.nId })[0];
              if (Util.objectCheck(item, item2)
              ) {
                list.push(item.nQjId);
              } else {
              }
            })
            if (list.length > 0) {
              let listItem = list.join(',')
              window['swal']("提示", "编号为" + listItem + '的数据没有修改,请修改数据后再保存', "warning")
            } else {
              //判断通过，则进行下一步流程
              that.saveApi(putBody);
            }
          }
        }
      } else {
        if (reviewList.length > 0) {
          window['swal']("提示", "复核中的流程不允许更改并保存", "warning")
        } else {
          //判断未经修改的条目录入数据不能进行保存
          let list: any = [];
          _.forEach(isChangeList, item => {
            let item2 = _.filter(that.cloneList, (it: any) => { return item.nId == it.nId })[0];
            if (Util.objectCheck(item, item2)
            ) {
              list.push(item.nQjId);
            } else {
            }
          })
          if (list.length > 0) {
            let listItem = list.join(',')
            window['swal']("提示", "编号为" + listItem + '的数据没有修改,请修改数据后再保存', "warning")
          } else {
            //判断通过，则进行下一步流程
            that.saveApi(putBody);
          }
        }
      }
    }
  }
  //搜索查询
  searchQuery() {
    let that = this;
    if (Util.dateOrder(that.postBody.sOprDateStart, that.postBody.sOprDateEnd)) {
      console.log(that.postBody.nBatchNoEnd);
      console.log(that.postBody.nBatchNoStart)
      if (that.postBody.nBatchNoEnd != '' && that.postBody.nBatchNoStart != '') {
        if (parseInt(that.postBody.nBatchNoEnd) > parseInt(that.postBody.nBatchNoStart)) {
          that.loadlist();
        } else {
          window['swal']("提示", "起始批次 须小于 结束批次", "warning");
        }
      } else {
        that.loadlist();
      }


    } else {
      window['swal']("提示", "发行日期 须早于 到期日期", "warning");
    }
  }
  //调用保存接口
  saveApi(item) {
    let that = this;
    window['swal']({
      type: "warning",
      showCancelButton: true,
      confirmButtonText: "确认",
      cancelButtonText: "取消",
      closeOnConfirm: false,
      showLoaderOnConfirm: true,
      title: "提示",
      text: "<div style='max-height: 200px;overflow-y: auto;'>" + "请确认是否保存选中的信息" + "</div>",
      html: true
    },
      function (isConfirm) {
        if (isConfirm) {
          that.routeModeService.save(item).subscribe(data => {
            if (data) {
              window['swal']("提示", "保存成功", "success");
              that.loadlist();
            }
          })
        }
      })
  }
  //提交
  commit() {
    let that = this;
    let checkedList: any = [];
    let checkedItem: any;
    let postBody: any = [];
    let sFlowStepList: any = [];
    let listData = _.cloneDeep(this.listData)
    if (this.proofInfo()) {
      _.forEach(listData, item => {
        let isNull: any = true;
        if (item.isChecked) {
          // delete item.nNdId;
          delete item.auditOpr;
          delete item.auditOprDate;
          delete item.auditOprZh;
          delete item.commitOpr;
          delete item.commitOprDate;
          delete item.commitOprZh;
          delete item.isChecked;

          //判断选中的对象的sFundType是否为数组
          if (Array.isArray(item.sFundType)) {
            item.sFundType = item.sFundType.join(',');
          }
          postBody.push(item);
          sFlowStepList.push(item.sFlowStep);
        }
      })
      // checkedItem = checkedList.join(',');
      let reviewList = _.filter(sFlowStepList, item => {
        return item == "2";
      })
      console.log(JSON.stringify(postBody))
      if (postBody.length == 0) {
        window['swal']("提示", "请选择需要操作的数据", "warning")
        // } else {
        //   this.showCommitModal(postBody)
        // }
      } else if (postBody.length > 1) {
        let list: any = [];
        _.forEach(postBody, it => {
          list.push(it.nBatchNo);
        })
        let repeatList = _.uniq(list);
        if (repeatList.length > 1) {
          window['swal']("提示", "请不要进行跨批次操作", "warning")
        } else {
          if (reviewList.length > 0) {
            window['swal']("提示", "请不要重复提交条目", "warning")
          } else {
            that.showCommitModal(postBody)
          }
        }
      } else {
        if (reviewList.length > 0) {
          window['swal']("提示", "请不要重复提交条目", "warning")
        } else {
          this.showCommitModal(postBody)
        }
      }
    }
  }
  //提交modal
  showCommitModal(item) {
    // 判断组件是否已创建，如果创建先注销
    if (this.commitComponent && this.commitComponent.instance) {
      this.commitComponent.destroy();
    }
    // 动态创建组件的实例
    const commitComponent = this.resolver.resolveComponentFactory(SubmitComponent);
    this.commitComponent = this.routeSubmitModal.createComponent(commitComponent);
    this.commitComponent.instance.RoutepostBody = item;
    this.commitComponent.instance.commitType = '在途模式';
    window['$']('#routeSubmitModal').modal('show');
  }
  //校验录入模式保存或者保存并提交时必填的6个字段
  proofInfo() {
    let allInfoList: any = [];
    _.forEach(this.listData, (item, index) => {
      let checkInfo: any = [];
      let checkItem: any;
      if (item.isChecked) {
        if (item.sFileSource == null || item.sFileSource == '') {
          checkInfo.push('条款出处')
        }
        if (item.sFundType == null || item.sFundType == '') {
          checkInfo.push('适用QDII类别')
        }
        if (item.sItemType == null || item.sItemType == '') {
          checkInfo.push('属性')
        }
        if (item.sFileName == null || item.sFileName == '') {
          checkInfo.push('文件名称')
        }
        if (item.f1 == null || item.f1 == '') {
          checkInfo.push('内容')
        }
        if (item.sFundGroupdsZh == null || item.sFundGroupdsZh == '') {
          checkInfo.push('适用QDII名称')
        }
        if (checkInfo.length > 0) {
          checkItem = checkInfo.join('、');
          let math = index + 1;
          allInfoList.push('序号为' + math + '的数据' + checkItem + '字段不能为空</br>')

        }

      }
    })
    if (allInfoList.length > 0) {
      window['swal'](
        {
          type: "warning",
          confirmButtonText: "确认",
          closeOnConfirm: true,
          title: "提示",
          text: "<div style='max-height: 200px;overflow-y: auto;'>" + allInfoList.join(' ') + "</div>",
          html: true
        }, function () {

        }
      );
      return false;
    } else {
      return true;
    }
  }
  //根据字典key查询value
  getValueByKey(key, dictionaryName) {
    let that = this;
    let info: any;
    let sFundType: any;
    console.log(key)
    switch (dictionaryName) {
      case 'QDII_RECORD_TYPE':
        info = _.filter(that.dictionaryList.QDII_RECORD_TYPE, (item: any) => {
          return item.sItemKey == key
        })
        break;
      case 'NX_SOURCE':
        info = _.filter(that.dictionaryList.NX_SOURCE, (item: any) => {
          return item.sItemKey == key
        })
        break;
      case 'QD_ACCOUNT_TYPE':
      let sFundTypelist: any = [];
      _.forEach(key, (it, ind) => {
        let list: any = _.filter(that.dictionaryList.QD_ACCOUNT_TYPE, (item: any) => { return item.sItemKey == it })[0].sItemValue

        sFundTypelist.push(list);
      })
      sFundType = sFundTypelist.join(',')
        break;
      case 'RISK_BOOLMBERG_CONTROL':
        info = _.filter(that.dictionaryList.RISK_BOOLMBERG_CONTROL, (item: any) => {
          return item.sItemKey == key
        })
        break;
    }
    if (dictionaryName == 'QD_ACCOUNT_TYPE') {
      return sFundType;
    } else {
      return info[0].sItemValue;
    }
  }
  // 修改标蓝(i为下标,value为修改后的值,name为字段名)
  inputChange(i: any, value: any, name: any) {
    let that = this;
    if (that.listData[i].sItemType != '' && that.listData[i].sItemType != null) {
      this.listData[i].sItemTypeZh = this.getValueByKey(that.listData[i].sItemType, 'QDII_RECORD_TYPE')
    } else {
      this.listData[i].sItemTypeZh = '';
    }

    if (that.listData[i].f4 != '' && that.listData[i].f4 != null) {
      this.listData[i].f4Zh = this.getValueByKey(that.listData[i].f4, 'RISK_BOOLMBERG_CONTROL')
    } else {
      this.listData[i].f4Zh = '';
    }

    if (that.listData[i].sFundType != '' && that.listData[i].sFundType != null) {
      this.listData[i].sFundTypeZh = this.getValueByKey(that.listData[i].sFundType, 'QD_ACCOUNT_TYPE')
    } else {
      this.listData[i].sFundTypeZh = '';
    }
    // if (that.listData[i].sFileSource != '' && that.listData[i].sFileSource != null) {
    //   this.listData[i].sFileSourceZh = this.getValueByKey(that.listData[i].sFileSource, 'NX_SOURCE')
    // }
    // 定位tr
    let index = i + 1;
    // 定位输入框和选择框
    let id = "#route-table tbody tr:nth-child(" + index + ") td div[id=" + name + "]";
    // let id2 = "#input-table tbody tr:nth-child(" + index + ") td select[name=" + name + "]";
    // 获取当前修改对象
    let item = this.cloneList[i];
    // 循环对象
    for (let key in item) {
      // 判断字段名是否相等
      if (key == name) {
        // 判断原值是否为null(后端空值返回null,前端空值为'',实际都为空,相等)
        if (item[key] == null) {
          if (value == '') {
            window['$'](id).removeClass('triangle-topleft');
          } else {
            window['$'](id).addClass('triangle-topleft');
          }
        } else {
          // 判断原值不为null,直接对比
          if (item[key] == value) {
            console.log("触发1")
            window['$'](id).removeClass('triangle-topleft');
          } else {
            console.log("触发2")
            window['$'](id).addClass('triangle-topleft');
          }
        }
      }
    }
  }
  //加锁
  // lock() {
  //   let that = this;
  //   let lockList: any = [];
  //   _.forEach(this.listData, item => {
  //     if (item.isChecked) {
  //       lockList.push(item.nId);
  //     }
  //   })
  //   console.log(lockList)
  //   let getBody = {
  //     "nIdList": lockList
  //   }
  //   if(lockList.length != 0){
  //     this.routeModeService.lock(getBody).subscribe(data => {
  //       if (data == true) {
  //         that.recall();
  //       } else {
  //         window['swal']("提示", "上锁失败", "warning");
  //       }
  //     })
  //   }else{
  //     window['swal']("提示", "请选择一条或者多条数据进行撤销", "warning")
  //   }

  // }
  //点击修改单元格字段状态
  changeEleStatus(index, field, type) {
    if (type == '1' && this.listData[index].sFlowStep == '1') {
      this.elementShow[index][field] = '1';
      // if (field == 'sFundType') {
      //   setTimeout(() => {
      //     Util.loadSelect(this.dictionaryList.QD_ACCOUNT_TYPE, 'QDIIRouteFundType' + index)
      //     window['$']('#QDIIRouteFundType' + index).selectpicker('val', this.listData[index].sFundType);
      //   }, 100);

      // }
    } else {
      // console.log("chufa")
      this.elementShow[index][field] = '';
    }

  }
  //添加空白数据进入elementList
  elementList(index) {
    this.elementShow = [];
    for (let i = 0; i < index; i++) {
      this.elementShow.push({
        sFileSource: "",//条款出处
        sFileName: "",//文件名称
        sItemType: "",//属性
        sFundType: [],//适用QDII类别
        sFundGroupds: "",//适用QDII名称
        sFundGroupdsZh: "",//适用QDII名称转义字段
        f1: "",//内容
        f3: "",//指标释义
        f4: "",//Bloomberg系统能否控制
        f5: "",//系统设置代码
        f6: "",//阀值
        f7: "",//人工控制方法说明
        f8: "",//系统实施相关条件
        f9: "",//备注1
        f10: ""//备注2
      })
    }
  }
}

